<script>
    var jqgridAllColsArr = ['goodsName', 'goodsSn', 'barCode', 'colorName', 'sizeName', 'quantity', 'price', 'discount', 'truePrice',
	    'trueAmount', 'businessTime', 'ordersSn', 'businessType', 'handlerName', 'trueTotalAmount', 'remark', 'categoryName', 'blandName', 'styleName', 'seasonName', 'year'];

    var detailListShowColsArr = ['goodsName', 'goodsSn', 'barCode', 'colorName', 'sizeName', 'quantity', 'price', 'discount', 'truePrice',
	    'trueAmount', 'businessTime', 'ordersSn', 'businessType', 'handlerName', 'trueTotalAmount',
	    'remark', 'categoryName', 'blandName', 'styleName', 'seasonName', 'year'];
    var groupBySkuListShowColsArr = ['goodsName', 'goodsSn', 'barCode', 'colorName', 'sizeName', 'categoryName', 'blandName', 'styleName', 'seasonName', 'year', 'quantity', 'price', 'discount', 'truePrice', 'trueAmount'];
    var groupByGoodListShowColsArr = ['goodsName', 'goodsSn', 'barCode', 'quantity', 'price', 'discount', 'truePrice', 'trueAmount', 'categoryName', 'blandName', 'styleName', 'seasonName', 'year'];
    var groupByOrderListShowColsArr = ['quantity', 'businessTime', 'ordersSn', 'type', 'businessType', 'handlerName', 'trueTotalAmount', 'remark'];
    var groupByHandlerListShowColsArr = ['quantity', 'trueAmount', 'handlerName'];

    var detailListSearchItemArr = ['searchKey', 'handler', 'ordersSn', 'category', 'bland', 'color', 'size', 'style', 'year', 'season', 'orderStatus', 'itemType', 'storeId'];
    var groupBySkuListSearchItemArr = ['searchKey', 'category', 'bland', 'color', 'size', 'style', 'year', 'season', 'orderStatus', 'itemType', 'storeId'];
    var groupByGoodListSearchItemArr = ['searchKey', 'category', 'bland', 'style', 'year', 'season', 'orderStatus', 'itemType', 'storeId'];
    var groupByOrderListSearchItemArr = ['handler', 'ordersSn', 'orderStatus', 'itemType', 'storeId'];
    var groupByHandlerListSearchItemArr = ['handler', 'orderStatus', 'itemType', 'storeId'];

    $(document).ready(function () {
	    $("#list_section").jqGrid({
		    cmTemplate: {
			    sortable: false
		    },
		    jsonReader: {
			    root: 'data',
			    page: 'current_page',
			    total: 'last_page',
			    records: 'total'
		    },
		    prmNames: {},
		    postData: {
			    beginTime: transferGMTStringtoBJTime(getDayBeginStr(new Date())),
			    endTime: transferGMTStringtoBJTime(getOffsetDayBeginStr(new Date(), 1))
		    },
		    url: '{{ route('admin.shop.report.purchase.purchaseDetailList') }}', // 传入后台的地址。
		    datatype: 'json',
		    multiselect: false,
		    multiSort: true,
		    colModel: [{
			    name: 'goodsName',
			    index: 'goodsName',
			    label: '商品名称',
			    frozen: true,
			    sortable: true
		    }, {
			    name: 'goodsSn',
			    index: 'goodsSn',
			    label: '货号',
			    align: "center",
			    width: 140,
			    frozen: true,
			    sortable: true
		    }, {
			    name: 'barCode',
			    index: 'barCode',
			    label: '条码',
			    align: "center",
			    width: 140,
			    frozen: true
		    },
			    {
				    name: 'colorName',
				    index: 'colorName',
				    width: 100,
				    label: '颜色',
				    formatter: colorNamesDecode,
				    unformat: colorNamesUndecode,
				    align: "center",
				    frozen: true
			    }, {
				    name: 'sizeName',
				    index: 'sizeName',
				    width: 100,
				    label: '尺码',
				    align: "center",
				    formatter: sizeNamesDecode,
				    unformat: sizeNamesUndecode,
				    frozen: true
			    }, {
				    name: 'blandName',
				    index: 'blandName',
				    label: '品牌',
				    formatter: blandNamesDecode,
				    align: "center",
				    width: 80
			    }, {
				    name: 'categoryName',
				    index: 'categoryName',
				    label: '分类',
				    align: "center",
				    formatter: categoryNamesDecode,
				    width: 80
			    }, {
				    name: 'styleName',
				    index: 'styleName',
				    width: 120,
				    align: 'center',
				    label: '款式'
			    }, {
				    name: 'seasonName',
				    index: 'seasonName',
				    label: '季节',
				    align: "center",
				    width: 80
			    }, {
				    name: 'year',
				    index: 'year',
				    label: '年份',
				    align: "center",
				    // formatter : yearFromater,
				    width: 90
			    }, {
				    name: 'quantity',
				    index: 'quantity',
				    label: "单品数量",
				    align: "right",
				    width: 100,
				    sortable: true
			    }, {
				    name: 'price',
				    index: 'price',
				    align: "right",
				    label: "单价",
				    width: 100,
				    sorttype: "float",
				    formatter: 'currency'
			    }, {
				    name: 'discount',
				    index: 'discount',
				    label: "折扣(%)",
				    align: "right",
				    formatter: 'number'
			    }, {
				    name: 'truePrice',
				    index: 'truePrice',
				    align: "right",
				    label: "折后价",
				    sorttype: "float",
				    formatter: 'currency'
			    }, {
				    name: 'trueAmount',
				    index: 'trueAmount',
				    label: "总金额",
				    align: "right",
				    sorttype: "float",
				    formatter: 'currency',
				    sortable: true
			    }, {
				    name: 'ordersSn',
				    index: 'ordersSn',
				    align: 'center',
				    formatter: viewOrder,
				    label: '采购单号',
				    width: 180
			    }, {
				    name: 'type',
				    index: 'type',
				    hidden: true,
				    label: 'type'
			    }, {
				    name: 'businessType',
				    index: 'businessType',
				    align: 'center',
				    label: '业务类别'
			    }, {
				    name: 'handlerName',
				    index: 'handlerName',
				    align: 'center',
				    label: '采购员',
				    sortable: true
			    }, {
				    name: 'trueTotalAmount',
				    index: 'trueTotalAmount',
				    label: "单据总金额",
				    align: "right",
				    sorttype: "float",
				    formatter: 'currency'
			    }, {
				    name: 'businessTime',
				    index: 'businessTime',
				    width: 130,
				    align: 'center',
				    label: '单据日期',
				    formatter: timeFormat,
				    sortable: true
			    }, {
				    name: 'remark',
				    index: 'remark',
				    align: 'center',
				    label: '单据备注'
			    }, {
				    name: 'id',
				    index: 'id',
				    hidden: true,
				    label: 'id'
			    }], // --显示的列。
		    pager: "#list_section_pager", // --得到分页的层
		    rownumbers: false, // --是否在表格最前端添加1列为自动编号
		    rowNum: 20, // --一页显示几行？
		    page: 1, // --从第几页开始
		    rowlist: [10, 20, 30], // --多少页一段
		    height: "100%",
		    width: "100%",
		    viewrecords: true,
		    autowidth: true,
		    shrinkToFit: false,
		    gridComplete: function () {
			    $("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
			    getScope("PurchaseReportModule").loadingData = false;
			    var dataListType = getScope("PurchaseReportModule").dataListType;
			    // 根据dataListType设置tab
			    $("ul#myTab li:not(." + dataListType + ")").removeClass("active").css("background-color", "white");
			    $("ul#myTab li." + dataListType).addClass("active");
		    },
		    loadComplete: function () {
			    adjustFrozenColumnHeight('list_section');
			    disableTarget(getScope('PurchaseReportModule').target, false);
		    },
		    loadError: function () {
			    disableTarget(getScope("PurchaseReportModule").target, false);
		    },
	    }).jqGrid('navGrid', '#list_section_pager', {
		    refresh: false,
		    add: false,
		    edit: false,
		    del: false,
		    search: false,
		    sortable: false
	    }, {
		    closeOnEscape: true,
		    closeAfterEdit: true
	    }, {
		    closeOnEscape: true,
		    closeAfterAdd: true,
		    serializeEditData: function (data) {
			    return $.param($.extend({}, data, {
				    id: ''
			    }));
		    }
	    });

	    // 自适应宽度
	    $(window).resize(function () {
		    $("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
	    });

	    //修复排序列表头样式
	    var myGrid = $("#list_section");
	    var cm = myGrid[0].p.colModel;
	    $.each(myGrid[0].grid.headers, function (index, value) {
		    var cmi = cm[index], colName = cmi.name;
		    if (cmi.sortable && colName !== 'rn' && colName !== 'cb' && colName !== 'subgrid') {
			    $('div.ui-jqgrid-sortable', value.el).addClass('sortable');
			    $('div.ui-jqgrid-sortable', value.el).prepend('<span class="sortable-icon"></span>');
		    }
	    });

	    // 设置jqgrid表头对齐方式
	    setGridLabelAlign('list_section', 'quantity,price,discount,truePrice,trueAmount,trueTotalAmount', 'right');
	    setGridLabelAlign('list_section', 'goodsName,goodsSn', 'left');
	    setGridLabelClass('list_section', 'quantity,trueAmount', 'sortable-align-fix');

	    // 冻结列
	    $("#list_section").jqGrid('setFrozenColumns');
	    adjustFrozenDivHeight('list_section');

	    /*if (onLoadFromGoodsSummary) {
		    var scope = getScope("PurchaseReportModule");
		    var queryvo = onLoadFromGoodsSummary;

		    scope.searchModel.timePeriod = 'other'
		    scope.searchModel.beginTime = new Date(queryvo.beginTime);
		    scope.searchModel.endTime = new Date(queryvo.endTime);
		    scope.searchModel.searchKey = queryvo.searchKey;
		    scope.showSearchTab = true;
		    setTimeout(function () {
			    scope.$apply(function (scope) {
				    scope.dataListType = 'groupBySkuList';
				    scope.searchList();
				    scope.getSumData();
			    });
		    }, 500);
	    }*/
    });

    var commodityApp = angular.module('JxApp', ['JxApp.mulsel', "checklist-model", "ui.bootstrap.tpls", 'ui.bootstrap.datepicker', 'JxApp.levelsel']);

    commodityApp.controller("PurchaseReportModule", function ($scope, $filter, $http, $timeout) {

	    $scope.loadingData = false;
	    $scope.dataListType = 'saleRetailList';

	    $scope.getSumData = function (searchParam) {
		    if (!searchParam) {
			    searchParam = angular.copy($scope.searchParam);
		    }

		    searchParam.beginTime = getDayBegin($scope.searchModel.beginTime);
		    searchParam.endTime = getOffsetDayBegin($scope.searchModel.endTime, 1);
		    searchParam.dataListType = $scope.dataListType;
		    $scope.sumDataLoading = true;
		    $http.get($scope.saleSumReportUrl, {params: searchParam}).success(function (result) {

			    $scope.sumQuantity = result.sumQuantity;
			    $scope.sumTrueAmount = result.sumTrueAmount;
			    $scope.sumOrdersCount = result.sumOrdersCount;

			    $scope.sumDataLoading = false;
		    });
	    };

	    $scope.init = function () {
		    $scope.showCountData = false;
		    $scope.searchModel = {
			    timePeriod: 'today',
			    beginTime: new Date(),
			    endTime: new Date(),
			    orderStatus: 2,
			    itemType: 'PURCHASE'
		    };

		    $scope.searchParam = {
			    beginTime: getDayBeginStr($scope.searchModel.beginTime),
			    endTime: getOffsetDayBeginStr($scope.searchModel.endTime, 1),
			    dataListType: $scope.dataListType
		    };

		    $scope.showSearchTab = true;
		    $scope.purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseDetailList') }}';
		    $scope.saleSumReportUrl = '{{ route('admin.shop.report.purchase.purchaseDetailListSum') }}';
		    $scope.sumDataLoading = true;
		    $scope.allCategory = allCategory;
		    $scope.curSearchItemArr = detailListSearchItemArr;
		    $scope.blands = strBlandListJson;
		    $scope.seasons = strSeasonListJson;
		    $scope.allYears = allYears;
		    $scope.allStyleJson = strStyleListJson;
		    $scope.allSizeJson = allSizes;
		    $scope.allColorJson = allColors;


		    $scope.getSumData({beginTime: getDayBegin(new Date()), endTime: getOffsetDayBegin(new Date(), 1)});

	    };

	    $scope.init();

	    $scope.getShowDataCountText = function () {
		    if ($scope.showCountData) {
			    return '收起统计数据';
		    } else {
			    return '展示统计数据';
		    }
	    };
	    $scope.changeShowDataCount = function () {
		    $scope.showCountData = !$scope.showCountData;
	    };
	    $scope.refreshTimePeriod = function () {
		    var vToday = new Date();
		    if (!$scope.searchModel.beginTime || !$scope.searchModel.endTime) {
			    $scope.searchModel.timePeriod = 'other';
		    } else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(vToday)
			    && getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(vToday)) {
			    $scope.searchModel.timePeriod = 'today';
		    } else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(getYesterday(vToday))
			    && getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(getYesterday(vToday))) {
			    $scope.searchModel.timePeriod = 'yesterday';
		    } else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(addDate(vToday, -6))
			    && getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(new Date())) {
			    $scope.searchModel.timePeriod = 'thisWeek';
		    } else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(addDate(vToday, -29))
			    && getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(new Date())) {
			    $scope.searchModel.timePeriod = 'thisMonth';
		    } else {
			    $scope.searchModel.timePeriod = 'other';
		    }
	    };

	    $scope.$watch('searchModel.beginTime', function () {
		    $scope.refreshTimePeriod();
	    });
	    $scope.$watch('searchModel.endTime', function () {
		    $scope.refreshTimePeriod();
	    });

	    //查询函数
	    $scope.searchList = function () {
		    $scope.loadingData = true;
		    var categoryIds = getChildIds(allCategoryList, $scope.searchModel.categoryId);
		    var vToday = new Date();
		    if ($scope.searchModel.timePeriod == 'today') {
			    $scope.searchModel.beginTime = vToday;
			    $scope.searchModel.endTime = vToday;
		    } else if ($scope.searchModel.timePeriod == 'yesterday') {
			    var vYesterday = getYesterday(vToday);
			    $scope.searchModel.beginTime = vYesterday;
			    $scope.searchModel.endTime = vYesterday;
		    } else if ($scope.searchModel.timePeriod == 'thisWeek') {
			    // 上周的今天再加1天
			    $scope.searchModel.beginTime = addDate(vToday, -6);
			    $scope.searchModel.endTime = vToday;
		    } else if ($scope.searchModel.timePeriod == 'thisMonth') {
			    // 上个月的今天再加1天
			    $scope.searchModel.beginTime = addDate(vToday, -29);
			    $scope.searchModel.endTime = vToday;
		    } else if ($scope.searchModel.timePeriod == 'all') {
			    $scope.searchModel.beginTime = '';
			    $scope.searchModel.endTime = '';
		    }


		    var searchParam = {
			    storeId: $scope.searchModel.storeId,
			    searchKey: $scope.searchModel.searchKey,
			    beginTime: transferGMTStringtoBJTime(getDayBeginStr($scope.searchModel.beginTime)),
			    endTime: transferGMTStringtoBJTime(getOffsetDayBeginStr($scope.searchModel.endTime, 1)),
			    handlerId: $scope.searchModel.handlerId,
			    ordersSn: $scope.searchModel.ordersSn,
			    categoryId: categoryIds,
			    blandId: $scope.searchModel.blandId,
			    colorId: $scope.searchModel.colorIds,
			    sizeId: $scope.searchModel.sizeIds,
			    styleId: $scope.searchModel.styleId,
			    year: $scope.searchModel.year,
			    seasonId: $scope.searchModel.seasonId,
			    orderStatus: $scope.searchModel.orderStatus,
			    itemType: $scope.searchModel.itemType,
			    dataListType: $scope.dataListType
		    };

		    if (!contains($scope.curSearchItemArr, 'searchKey')) {
			    delete searchParam.searchKey;
		    }

		    if (!contains($scope.curSearchItemArr, 'handler')) {
			    delete searchParam.handlerId;
		    }

		    if (!contains($scope.curSearchItemArr, 'ordersSn')) {
			    delete searchParam.ordersSn;
		    }

		    if (!contains($scope.curSearchItemArr, 'category')) {
			    delete searchParam.categoryId;
		    }

		    if (!contains($scope.curSearchItemArr, 'bland')) {
			    delete searchParam.blandId;
		    }

		    if (!contains($scope.curSearchItemArr, 'color')) {
			    delete searchParam.colorId;
		    }

		    if (!contains($scope.curSearchItemArr, 'size')) {
			    delete searchParam.sizeId;
		    }

		    if (!contains($scope.curSearchItemArr, 'style')) {
			    delete searchParam.styleId;
		    }

		    if (!contains($scope.curSearchItemArr, 'year')) {
			    delete searchParam.year;
		    }

		    if (!contains($scope.curSearchItemArr, 'season')) {
			    delete searchParam.seasonId;
		    }

		    if (!contains($scope.curSearchItemArr, 'itemType')) {
			    delete searchParam.itemType;
		    }

		    // 手动清空postdata
		    $("#list_section").setGridParam({
			    postData: null
		    });
		    $("#list_section").setGridParam({
			    postData: {
				    page: 1
			    }
		    });
		    //取消上个button禁用
		    disableTarget($scope.target, false, true);
		    $scope.target = getEvtTarget();
		    disableTarget($scope.target, true);
		    $("#list_section").jqGrid("setGridParam", {
			    postData: searchParam,
			    url: $scope.purchaseReportUrl
			    // 传入后台的地址。
		    }).trigger("reloadGrid", [{
			    page: 1
		    }]); // 重新载入Grid表格

		    //保存最后一次查询结果对应的查询条件,以供用作获取统计数据的查询条件
		    $scope.searchParam = searchParam;
	    };

	    $scope.isShowSearchItem = function (itemName) {
		    return contains($scope.curSearchItemArr, itemName);
	    };
    });

    $(document).on('click.modal.data-api', '[data-toggle="modal-filter"]', function (e) {
	    var $this = $(this);
	    var modalUrl = $(this).data('url');

	    var sidxParam = '';
	    var sordParam = '';

	    var postData = $("#list_section").jqGrid("getGridParam", "postData");

	    if (postData.sidx) {
		    sidxParam = '&sidx=' + postData.sidx;
	    }

	    if (postData.sord) {
		    sordParam = '&sord=' + postData.sord;
	    }

	    var purchaseReportUrl = getScope("PurchaseReportModule").purchaseReportUrl;
	    var searchParam = getScope("PurchaseReportModule").searchParam;

	    var url = '{{ route('admin.shop.report.purchase.purchaseDetailListExcel') }}?jsonUrl=' + purchaseReportUrl + sidxParam + sordParam + '&' + $.param(searchParam);


	    $(this).data('link', url);

	    if (modalUrl) {
		    var $target = $($this.attr('data-target'));
		    $target.modal('show');
		    $target.html('').load(modalUrl, function () {

		    });
	    }
    });

    var getChildIds = function (list, startPid) {
	    var ids = startPid;

	    if (startPid != undefined && startPid != '') {
		    if (list != undefined && list.length > 0) {
			    for (var i = 0; i < list.length; i++) {
				    if (list[i]['pid'] == startPid) {
					    ids = ids + ',' + getChildIds(list, list[i]['id']);
				    }
			    }

			    return ids;
		    } else {
			    return startPid;
		    }
	    } else {
		    return '';
	    }

    };

    /**
     * 跳转单据链接
     */
    function viewOrder(cellvalue, options, rowdata) {
	    if (rowdata.ordersSn) {
		    if (rowdata.type == 'PURCHASE') {
			    return '<a href="'
				    + '{{ route('admin.shop.purchase.show') }}?order_no='
				    + rowdata.ordersSn + '" target="_blank">'
				    + rowdata.ordersSn + '</a>';
		    } else {
			    return '<a href="'
				    + '{{ route('admin.shop.reject.show')}}?order_no='
				    + rowdata.ordersSn + '" target="_blank">'
				    + rowdata.ordersSn + '</a>';
		    }
	    }
    }

    /**
     * 显示“是”或者“否” 1-是 2-否
     */
    function yearFromater(cellvalue, options, rowdata) {
	    if (!cellvalue) {
		    return '';
	    } else if (parseFloat(cellvalue) - parseInt(cellvalue) == 0.5) {
		    return cellvalue == '' ? '' : (parseInt(cellvalue) + '下');
	    } else {
		    return cellvalue == '' ? '' : (parseInt(cellvalue) + '上');
	    }
    }

    /**
     * 标签页切换事件
     */
    $('#myTab a').click(function (e) {
	    if (getScope("PurchaseReportModule").loadingData) {
		    return;
	    }

	    e.preventDefault();

	    $(this).tab('show');
    });

    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
	    if (getScope("PurchaseReportModule").loadingData) {
		    return;
	    }

	    if ($(e.target).attr('href') == "#saleRetailList") {
		    getScope("PurchaseReportModule").dataListType = 'saleRetailList';
		    getScope("PurchaseReportModule").purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseDetailList') }}';
		    getScope("PurchaseReportModule").$apply(function (scope) {
			    scope.curSearchItemArr = detailListSearchItemArr;
		    });
		    setGridColDisplay(detailListShowColsArr);
	    } else if ($(e.target).attr('href') == "#groupBySkuList") {
		    getScope("PurchaseReportModule").dataListType = 'groupBySkuList';
		    getScope("PurchaseReportModule").purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseGroupBySkuList') }}';
		    getScope("PurchaseReportModule").$apply(function (scope) {
			    scope.curSearchItemArr = groupBySkuListSearchItemArr;
		    });
		    setGridColDisplay(groupBySkuListShowColsArr);
	    } else if ($(e.target).attr('href') == "#groupByGoodList") {
		    getScope("PurchaseReportModule").dataListType = 'groupByGoodList';
		    getScope("PurchaseReportModule").purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseGroupByGoodList') }}';
		    getScope("PurchaseReportModule").$apply(function (scope) {
			    scope.curSearchItemArr = groupByGoodListSearchItemArr;
		    });
		    setGridColDisplay(groupByGoodListShowColsArr);
	    } else if ($(e.target).attr('href') == "#groupByOrderList") {
		    getScope("PurchaseReportModule").dataListType = 'groupByOrderList';
		    getScope("PurchaseReportModule").purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseGroupByOrderList') }}';
		    getScope("PurchaseReportModule").$apply(function (scope) {
			    scope.curSearchItemArr = groupByOrderListSearchItemArr;
		    });
		    setGridColDisplay(groupByOrderListShowColsArr);
	    } else if ($(e.target).attr('href') == "#groupByHandlerList") {
		    getScope("PurchaseReportModule").dataListType = 'groupByHandlerList';
		    getScope("PurchaseReportModule").purchaseReportUrl = '{{ route('admin.shop.report.purchase.purchaseGroupByHandlerList') }}';
		    getScope("PurchaseReportModule").$apply(function (scope) {
			    scope.curSearchItemArr = groupByHandlerListSearchItemArr;
		    });
		    setGridColDisplay(groupByHandlerListShowColsArr);
	    }

	    // 清除列表数据
	    $("#list_section").jqGrid("clearGridData");
	    getScope("PurchaseReportModule").searchList();
	    getScope("PurchaseReportModule").getSumData();
    });


    //等候提示窗口
    $("#waitingDialog").dialog({
	    autoOpen: false,
	    show: {
		    effect: "blind",
		    duration: 10
	    },
	    position: ['middle', 200],
	    width: 300,
	    height: 134,
	    modal: true,
	    resizable: false,
	    open: function () {
	    },
	    dialogClass: "waitingDialog"
    });

    /*回车事件*/
    $('#searchForm').keypress(function (e) {
	    if (e.keyCode == '13') {
		    stopEvent(e);
		    $('#searchBtn').click();
	    }
    });

    //设置jgrid表头对齐方式
    function setGridLabelAlign(gridId, colNames, alignType) {
	    var colNameArr = [];
	    if (colNames != undefined) {
		    colNameArr = colNames.split(',');
	    }
	    for (var i = 0; i < colNameArr.length; i++) {
		    $("#" + gridId).jqGrid("setLabel", colNameArr[i], "", {
			    "text-align": alignType
		    });
	    }
    }

    //设置jgrid表头样式
    function setGridLabelClass(gridId, colNames, css) {
	    var colNameArr = [];
	    if (colNames != undefined) {
		    colNameArr = colNames.split(',');
	    }
	    for (var i = 0; i < colNameArr.length; i++) {
		    $("#" + gridId).jqGrid("setLabel", colNameArr[i], "", css);
	    }
    }

    //设置jgrid列是否显示
    function setGridColDisplay(showColsArr) {
	    $("#list_section").jqGrid('destroyFrozenColumns');
	    for (var i = 0; i < jqgridAllColsArr.length; i++) {
		    if (contains(showColsArr, jqgridAllColsArr[i])) {
			    $("#list_section").setGridParam().showCol(jqgridAllColsArr[i]);
		    } else {
			    $("#list_section").setGridParam().hideCol(jqgridAllColsArr[i]);
		    }
	    }
	    $("#list_section").jqGrid('setFrozenColumns');
    }

    /* 修复Jqgrid冻结列高度函数 */
    function adjustFrozenDivHeight(listId) {
	    var bdivTop = -1;

	    if (navigator.userAgent.toLowerCase().match(/opera/)) {
		    divTop = 0;
		    bdivTop = 0;
	    }

	    $('#gview_' + listId + ' .frozen-bdiv').css({
		    top: $('#gview_' + listId + ' .frozen-bdiv').position().top + bdivTop
	    });
    }

    //检查每一行冻结行高度是否和未冻结行高度一致
    function adjustFrozenColumnHeight(listId) {
	    $('#' + listId + '_frozen tr').slice(1).each(function () {

		    var frozenTdHeight = parseFloat($('td:first', this).height());
		    var normalHeight = parseFloat($(' #' + listId + ' #' + $(this).attr('id')).find('td:first').height());

		    // 如果冻结的列高度小于未冻结列的高度则hack之
		    if (frozenTdHeight != normalHeight) {

			    $('td', this).each(function () {

				    /* 浏览器差异高度hack */
				    var space = 0; // opera默认使用0就可以
				    /*				if (navigator.userAgent.toLowerCase().match(/chrome/)) {
                                        space = 0.6;
                                    } else if (navigator.userAgent.toLowerCase().match(/msie/)) {
                                        space = -0.2;
                                    } else if (navigator.userAgent.toLowerCase().match(/mozilla/)) {
                                        space = 0.3;
                                    }*/
				    $(this).style('height', parseFloat(normalHeight + space) + "px", 'important');
				    /*
                     * div.style('color', 'blue', 'important');
                     * $(this).css("cssText","height:"+parseFloat(normalHeight +
                     * space)+"px !important");
                     */
				    /*
                     * if (!$(this).attr('style') ||
                     * $(this).attr('style').indexOf('height:') == -1) {
                     * $(this).attr('style', $(this).attr('style') + ";height:" +
                     * (normalHeight + space) + "px !important"); }
                     */
			    });
		    }
		    $('#gview_' + listId + ' .ui-jqgrid-bdiv:eq(1)').style('height', $('#gview_' + listId + ' .ui-jqgrid-bdiv:first').height() + 'px', 'important');

	    });

	    $('#gview_' + listId + ' .frozen-bdiv').style('height', $('table#' + listId + '_frozen').height() + 'px', 'important');//避免冻结的DIV挡住列表的横向滚动条
    }

    /**
     * 分类ID转为分类名称
     */
    function categoryNamesDecode(cellvalue, options, rowdata) {
	    if (cellvalue) {

		    var nameTemp = getObject(allCategoryList, 'id', cellvalue);

		    if (nameTemp) {
			    return nameTemp.name;
		    } else {
			    return '';
		    }

	    } else {
		    return '';
	    }
    }

    /**
     * 颜色ID串转为颜色名称串
     */
    function colorNamesDecode(cellvalue, options, rowdata) {
	    if (cellvalue) {
		    cellvalue = eval("\'" + cellvalue + "\'");
		    var ids = cellvalue.split(',');
		    var nameTemp;
		    var nameList = [];
		    var allColor = getScope('PurchaseReportModule').allColorJson;
		    for (var i = 0; i < ids.length; i++) {
			    nameTemp = getObject(allColor, 'id', parseInt(ids[i]));
			    if (nameTemp) {
				    nameList.push(nameTemp);
			    }
		    }
		    nameList.sort(function (a, b) {
			    if (a['showOrder'] > b['showOrder']) {
				    return 1;
			    }
			    if (a['showOrder'] < b['showOrder']) {
				    return -1;
			    }
			    if (a['id'] > b['id']) {
				    return 1;
			    }
			    if (a['id'] < b['id']) {
				    return -1;
			    }
			    return 0;
		    });

		    return nameList.map(function (elem) {
			    return elem.name;
		    }).join();
	    } else {
		    return '';
	    }
    }

    /**
     * 颜色名称串转为颜色ID串
     */
    function colorNamesUndecode(cellvalue, options, rowdata) {
	    if (cellvalue) {
		    cellvalue = eval("\'" + cellvalue + "\'");
		    var names = cellvalue.split(',');
		    var idTemp = '';
		    var ids = '';
		    var allColor = getScope('PurchaseReportModule').allColorJson;
		    for (var i = 0; i < names.length; i++) {
			    idTemp = getObject(allColor, 'name', names[i]);
			    if (idTemp) {
				    ids = ids + ',' + idTemp.id;
			    }
		    }
		    if (ids) {
			    ids = ids.substr(1);
		    } else {
			    ids = '';
		    }
		    return ids;
	    } else {
		    return '';
	    }
    }

    /**
     * 尺码ID串转为尺码名称串
     */
    function sizeNamesDecode(cellvalue, options, rowdata) {
	    if (cellvalue) {
		    cellvalue = eval("\'" + cellvalue + "\'");
		    var ids = cellvalue.split(',');
		    var nameTemp;
		    var nameList = [];
		    var allSize = getScope('PurchaseReportModule').allSizeJson;
		    for (var i = 0; i < ids.length; i++) {
			    nameTemp = getObject(allSize, 'id', parseInt(ids[i]));
			    if (nameTemp) {
				    nameList.push(nameTemp);
			    }
		    }
		    nameList.sort(function (a, b) {
			    if (a['showOrder'] > b['showOrder']) {
				    return 1;
			    }
			    if (a['showOrder'] < b['showOrder']) {
				    return -1;
			    }
			    if (a['id'] > b['id']) {
				    return 1;
			    }
			    if (a['id'] < b['id']) {
				    return -1;
			    }
			    return 0;
		    });

		    return nameList.map(function (elem) {
			    return elem.name;
		    }).join();
	    } else {
		    return '';
	    }
    }

    /**
     * 尺码名称串转为尺码ID串
     */
    function sizeNamesUndecode(cellvalue, options, rowdata) {
	    if (cellvalue) {
		    cellvalue = eval("\'" + cellvalue + "\'");
		    var names = cellvalue.split(',');
		    var idTemp = '';
		    var ids = '';
		    var allSize = getScope('PurchaseReportModule').allSizeJson;
		    for (var i = 0; i < names.length; i++) {
			    idTemp = getObject(allSize, 'name', names[i]);
			    if (idTemp) {
				    ids = ids + ',' + idTemp.id;
			    }
		    }
		    if (ids) {
			    ids = ids.substr(1);
		    } else {
			    ids = '';
		    }
		    return ids;
	    } else {
		    return '';
	    }
    }

    /**
     * 品牌ID转为品牌名称
     */
    function blandNamesDecode(cellvalue, options, rowdata) {
	    if (cellvalue) {

		    var nameTemp = getObject(strBlandListJson, 'id', cellvalue);

		    if (nameTemp) {
			    return nameTemp.name;
		    } else {
			    return '';
		    }

	    } else {
		    return '';
	    }
    }
</script>